/*
** 2521.c
** 
** Made by (seakage2h)
** Login   <seakage2h@seakage2h-ubuntu>
** 
** Started on  Sun Sep 21 21:27:14 2008 seakage2h
** Last update Sun May 12 01:17:25 2002 Speed Blue
*/

/*
 * A little tricky problem
 */

/* #include "2521.h" */
#include <stdio.h>

int main()
{
     int N, M, P, C;

     while(scanf("%d%d%d%d", &N, &M, &P, &C)){
	  if (N + M + P + C == 0)
	       break;
	  if (M < P)
	       printf("%d\n", C+N-(M+C-P)); /* may income some true money */
	  else printf("%d\n", N+P-M); /* all fake money, poor James.... */
     }
     
     return 0;
}
